<!DOCTYPE html>

<html class="theme-next mist use-motion" lang="zh-Hans">

<head>
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport"
                                                                                  content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="theme-color" content="#222">

  <link rel="stylesheet" href="/lib/needsharebutton/needsharebutton.css">

  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">

  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">

  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet"
                                                                                  type="text/css">

  <link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet"
                                                                                  type="text/css">

  <link href="/css/main.css?v=6.0.1" rel="stylesheet" type="text/css">

  <link rel="icon" type="image/png" sizes="16x16"
                                                                                  href="/images/favicon.ico?v=6.0.1">

  <script type="text/javascript" id="hexo.configurations">
    var NexT = window.NexT || {};
    var CONFIG = {
      root: '/',
      scheme: 'Mist',
      version: '6.0.1',
      sidebar: {
        "position": "left",
        "display": "post",
        "offset": 12,
        "b2t": true,
        "scrollpercent": true,
        "onmobile": true
      },
      fancybox: true,
      fastclick: false,
      lazyload: true,
      tabs: true,
      motion: {
        "enable": true,
        "async": false,
        "transition": {
          "post_block": "fadeIn",
          "post_header": "slideDownIn",
          "post_body": "slideDownIn",
          "coll_header": "slideLeftIn",
          "sidebar": "slideUpIn"
        }
      },
      algolia: {
        applicationID: '',
        apiKey: '',
        indexName: '',
        hits: {
          "per_page": 10
        },
        labels: {
          "input_placeholder": "Search for Posts",
          "hits_empty": "We didn't find any results for the search: ${query}",
          "hits_stats": "${hits} results found in ${time} ms"
        }
      }
    };

  </script>

  <link rel="stylesheet" href="mermaid.min.css">
  <script src="https://unpkg.com/mermaid@7.1.0/dist/mermaid.min.js"></script>

  <meta name="keywords" content="python,爬虫,二次元,">

  <meta name="keywords" content="python,爬虫,二次元">
  <meta property="og:type" content="article">
  <meta property="og:title" content="半次元爬虫 banciyuan-downloader v2.0 更新">
  <meta property="og:url"
                                                                                  content="https://tankeryang.github.io/posts/半次元爬虫-banciyuan-downloader-v2-0-更新/index.html">
  <meta property="og:site_name" content="淦">
  <meta property="og:locale" content="zh-Hans">
  <meta property="og:image"
                                                                                  content="https://tankeryang.github.io/posts/半次元爬虫-banciyuan-downloader-v2-0-更新/pic0.png">
  <meta property="og:updated_time" content="2019-10-09T17:06:09.623Z">
  <meta name="twitter:card" content="summary">
  <meta name="twitter:title" content="半次元爬虫 banciyuan-downloader v2.0 更新">
  <meta name="twitter:image"
                                                                                  content="https://tankeryang.github.io/posts/半次元爬虫-banciyuan-downloader-v2-0-更新/pic0.png">

  <title>半次元爬虫 banciyuan-downloader v2.0 更新 | 淦</title>

  <noscript>
    <style type="text/css">
      .use-motion .motion-element,
      .use-motion .brand,
      .use-motion .menu-item,
      .sidebar-inner,
      .use-motion .post-block,
      .use-motion .pagination,
      .use-motion .comments,
      .use-motion .post-header,
      .use-motion .post-body,
      .use-motion .collection-title {
        opacity: initial;
      }

      .use-motion .logo,
      .use-motion .site-title,
      .use-motion .site-subtitle {
        opacity: initial;
        top: initial;
      }

      .use-motion {
        .logo-line-before i {
          left: initial;
        }

        .logo-line-after i {
          right: initial;
        }
      }

    </style>
  </noscript><!-- hexo-inject:begin --><!-- hexo-inject:end -->

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  <!-- hexo-inject:begin --><!-- hexo-inject:end --><div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope
                                                                                    itemtype="http://schema.org/WPHeader">
      <div class="header-inner">
        <div class="site-brand-wrapper">
          <div class="site-meta ">

            <div class="custom-logo-site-title">
              <a href="/" class="brand" rel="start">
                <span class="logo-line-before"><i></i></span>
                <span class="site-title">淦</span>
                <span class="logo-line-after"><i></i></span>
              </a>
            </div>

            <p class="site-subtitle">n*m*lg(b)</p>

          </div>

          <div class="site-nav-toggle">
            <button>
              <span class="btn-bar"></span>
              <span class="btn-bar"></span>
              <span class="btn-bar"></span>
            </button>
          </div>
        </div>

        <nav class="site-nav">

          <ul id="menu" class="menu">

            <li class="menu-item menu-item-home">
              <a href="/" rel="section">
                <i class="menu-item-icon fa fa-fw fa-home"></i> <br>home</a>
            </li>

            <li class="menu-item menu-item-archives">
              <a href="/archives/" rel="section">
                <i class="menu-item-icon fa fa-fw fa-archive"></i>
                <br>archives<span class="badge">16</span>
              </a>
            </li>

            <li class="menu-item menu-item-ml-note">
              <a href="/MachineLearningNote" rel="section">
                <i class="menu-item-icon fa fa-fw fa-book"></i> <br>ML Note</a>
            </li>

            <li class="menu-item menu-item-about">
              <a href="/about/" rel="section">
                <i class="menu-item-icon fa fa-fw fa-user"></i> <br>about</a>
            </li>

            <li class="menu-item menu-item-search">

              <a href="javascript:;" class="popup-trigger">

                <i class="menu-item-icon fa fa-search fa-fw"></i> <br>search</a>
            </li>

          </ul>

          <div class="site-search">

            <div class="popup search-popup local-search-popup">
              <div class="local-search-header clearfix">
                <span class="search-icon">
                  <i class="fa fa-search"></i>
                </span>
                <span class="popup-btn-close">
                  <i class="fa fa-times-circle"></i>
                </span>
                <div class="local-search-input-wrapper">
                  <input autocomplete="off" placeholder="searching..." spellcheck="false" type="text"
                                                                                                  id="local-search-input">
                </div>
              </div>
              <div id="local-search-result"></div>
            </div>

          </div>

        </nav>
      </div>
    </header>

    <a href="https://github.com/tankeryang" class="github-corner" target="_blank" title="Follow me on GitHub"
                                                                                    aria-label="Follow me on GitHub"><svg
                                                                                      width="80"
                                                                                      height="80"
                                                                                      viewbox="0 0 250 250"
                                                                                      style="fill:#222; color:#fff; position: absolute; top: 0; border: 0; right: 0;"
                                                                                      aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z" />
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
                                                                                        fill="currentColor"
                                                                                        style="transform-origin: 130px 106px;"
                                                                                        class="octo-arm" />
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
                                                                                        fill="currentColor"
                                                                                        class="octo-body" />
        </svg></a>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">

            <div id="posts" class="posts-expand">

              <div class="reading-progress-bar"></div>

              <article class="post post-type-normal" itemscope
                                                                                              itemtype="http://schema.org/Article">

                <div class="post-block">
                  <link itemprop="mainEntityOfPage"
                                                                                                  href="https://tankeryang.github.io/posts/半次元爬虫-banciyuan-downloader-v2-0-更新/">

                  <span hidden itemprop="author" itemscope
                                                                                                  itemtype="http://schema.org/Person">
                    <meta itemprop="name" content="tankeryang">
                    <meta itemprop="description" content>
                    <meta itemprop="image" content="/uploads/girl.jpeg">
                  </span>

                  <span hidden itemprop="publisher" itemscope
                                                                                                  itemtype="http://schema.org/Organization">
                    <meta itemprop="name" content="淦">
                  </span>

                  <header class="post-header">

                    <h1 class="post-title" itemprop="name headline">半次元爬虫
                      banciyuan-downloader v2.0 更新</h1>

                    <div class="post-meta">
                      <span class="post-time">

                        <span class="post-meta-item-icon">
                          <i class="fa fa-calendar-o"></i>
                        </span>

                        <span class="post-meta-item-text">posted on</span>

                        <time title="创建于" itemprop="dateCreated datePublished"
                                                                                                        datetime="2018-06-20T11:01:33+00:00">2018-06-20</time>

                      </span>

                      <span class="post-category">

                        <span class="post-meta-divider">|</span>

                        <span class="post-meta-item-icon">
                          <i class="fa fa-folder-o"></i>
                        </span>

                        <span class="post-meta-item-text">in</span>

                        <span itemprop="about" itemscope
                                                                                                        itemtype="http://schema.org/Thing"><a
                                                                                                          href="/categories/python/"
                                                                                                          itemprop="url"
                                                                                                          rel="index"><span
                                                                                                            itemprop="name">python</span></a></span>

                      </span>

                      <span class="post-comments-count">
                        <span class="post-meta-divider">|</span>
                        <span class="post-meta-item-icon">
                          <i class="fa fa-comment-o"></i>
                        </span>
                        <a href="/posts/半次元爬虫-banciyuan-downloader-v2-0-更新/#comments"
                                                                                                        itemprop="discussionUrl">
                          <span class="post-comments-count valine-comment-count" data-xid="/posts/半次元爬虫-banciyuan-downloader-v2-0-更新/"
                                                                                                          itemprop="commentCount"></span>
                        </a>
                      </span>

                      <span id="/posts/半次元爬虫-banciyuan-downloader-v2-0-更新/" class="leancloud_visitors"
                                                                                                      data-flag-title="半次元爬虫 banciyuan-downloader v2.0 更新">
                        <span class="post-meta-divider">|</span>
                        <span class="post-meta-item-icon">
                          <i class="fa fa-eye"></i>
                        </span>

                        <span class="post-meta-item-text">read times&#58;</span>

                        <span class="leancloud-visitors-count"></span>
                      </span>

                      <div class="post-wordcount">

                        <span class="post-meta-item-icon">
                          <i class="fa fa-file-word-o"></i>
                        </span>

                        <span class="post-meta-item-text">words
                          count&#58;</span>

                        <span title="words count">3k</span>

                        <span class="post-meta-divider">|</span>

                        <span class="post-meta-item-icon">
                          <i class="fa fa-clock-o"></i>
                        </span>

                        <span class="post-meta-item-text">minutes to read
                          &asymp;</span>

                        <span title="minutes to read">0:07</span>

                      </div>

                    </div>
                  </header>

                  <div class="post-body" itemprop="articleBody">

                    <img
                                                                                                    src="/posts/半次元爬虫-banciyuan-downloader-v2-0-更新/pic0.png">
                    <a id="more"></a>
                    <hr>
                    <p>这段时间<a href="https://bcy.net" target="_blank"
                                                                                                      rel="noopener">半次元</a>前端做了很大的改动，先后更新了两版，之前的小版本<code>v1.1</code>也不能用了，索性更新了<a
                                                                                                      href="https://github.com/tankeryang/banciyuan-downloader"
                                                                                                      target="_blank"
                                                                                                      rel="noopener">banciyuan-downloader
                        v2.0</a>版本，做了很大的改变，代码全部封装到<code>Downloader</code>类里，下面是更新内容
                    </p>
                    <h1 id="banciyuan-downloader-v2-0"><a href="#banciyuan-downloader-v2-0" class="headerlink"
                                                                                                      title="banciyuan-downloader v2.0"></a>banciyuan-downloader
                      v2.0</h1>
                    <ul>
                      <li>更新时间: <code>2018-06-18</code></li>
                    </ul>
                    <h2 id="更新原因"><a href="#更新原因" class="headerlink"
                                                                                                      title="更新原因"></a>更新原因
                    </h2>
                    <ul>
                      <li>半次元前端改版，需要重写脚本以适应HTML解析</li>
                      <li>半次元登录认证改为通过cookie表单传递认证，需重写登录方法</li>
                      <li>脚本太乱，需进行封装</li>
                    </ul>
                    <h2 id="更新内容"><a href="#更新内容" class="headerlink"
                                                                                                      title="更新内容"></a>更新内容
                    </h2>
                    <h3 id="模块化"><a href="#模块化" class="headerlink"
                                                                                                      title="模块化"></a>模块化
                    </h3>
                    <p>将方法封装到类<code>Downloader</code>里，优化接口方法，可提供外部调用</p>
                    <h3 id="实现功能"><a href="#实现功能" class="headerlink"
                                                                                                      title="实现功能"></a>实现功能
                    </h3>
                    <ul>
                      <li style="list-style: none"><input type="checkbox"
                                                                                                        checked>
                        根据<code>coser_id</code>批量下载某个coser发布的作品的所有图片</li>
                      <li style="list-style: none"><input type="checkbox"
                                                                                                        checked>
                        图片保存在以
                        <strong>coser名</strong> 命名的文件夹内</li>
                      <li style="list-style: none"><input type="checkbox"
                                                                                                        checked>
                        图片按
                        <strong>coser发布的作品</strong> 分文件夹保存，文件夹命名以
                        <strong>作品标签</strong> 拼接而成</li>
                      <li style="list-style: none"><input type="checkbox"
                                                                                                        checked>
                        若有相同标题的作品，则命名文件夹时会加上 <strong>顺序编号后缀</strong> 防止文件名冲突
                      </li>
                      <li style="list-style: none"><input type="checkbox"
                                                                                                        checked>
                        图片命名格式为<code>%num%.jpg</code>/<code>%num%.png</code>，其中<code>%num%</code>为从<code>1</code>开始的
                        <strong>编号</strong></li>
                      <li style="list-style: none"><input type="checkbox"
                                                                                                        checked>
                        支持智能下载
                        <strong>本地没有的作品</strong>，本地已有的作品 <strong>不会</strong>
                        重复下载</li>
                      <li style="list-style: none"><input type="checkbox"
                                                                                                        checked>
                        支持
                        <strong>断点续传</strong>
                        （从断连作品的下一个作品开始下载，若断连作品没下载完，则会丢失一部分断连作品的图片，其余均不影响）</li>
                      <li style="list-style: none"><input type="checkbox"
                                                                                                        checked>
                        支持超时自动重试
                      </li>
                      <li style="list-style: none"><input type="checkbox"
                                                                                                        checked>
                        支持下载指定作品
                      </li>
                      <li style="list-style: none"><input type="checkbox"
                                                                                                        checked>
                        根据频繁I/O进行
                        <strong>多线程优化</strong></li>
                      <li style="list-style: none"><input type="checkbox">
                        不支持无半次元账号的下载，因为有
                        <strong>只有粉丝可见</strong> 的限制，最好注册一个半次元账号</li>
                      <li style="list-style: none"><input type="checkbox">
                        只有粉丝可见的作品需关注该coser后方可下载</li>
                      <li style="list-style: none"><input type="checkbox">
                        暂时不支持只下载<code>COS</code>类的作品，因为半次元改版后没有对<code>COS</code>和<code>绘画</code>之类的做分类，都在同一<code>url</code>下
                      </li>
                    </ul>
                    <h3 id="依赖的库"><a href="#依赖的库" class="headerlink"
                                                                                                      title="依赖的库"></a>依赖的库
                    </h3>
                    <p>我的测试环境:</p>
                    <ul>
                      <li>python 3.6.4</li>
                      <li>beautifulsoup 4.5.3</li>
                      <li>requests 2.13.0</li>
                      <li>lxml 3.7.2</li>
                    </ul>
                    <h3 id="如何使用"><a href="#如何使用" class="headerlink"
                                                                                                      title="如何使用"></a>如何使用
                    </h3>
                    <ul>
                      <li>
                        <p>直接运行<code>run.py</code></p>
                        <p> 先执行:</p>
                        <figure class="highlight python">
                          <table>
                            <tr>
                              <td class="gutter">
                                <pre><span class="line">1</span><br></pre>
                              </td>
                              <td class="code">
                                <pre><span class="line">python run.py</span><br></pre>
                              </td>
                            </tr>
                          </table>
                        </figure>
                        <p> 后续步骤参考<a href="https://github.com/tankeryang/banciyuan-downloader#usage" target="_blank"
                                                                                                          rel="noopener">v1.0的Usage</a>
                        </p>
                      </li>
                      <li>
                        <p>自定义实现</p>
                        <p> 因为进行了
                          <strong>模块化</strong>，所以可以自行实例化一个<code>Downloader</code>对象来调用方法实现功能，下面给出简单例子:
                        </p>
                        <p> <strong>分部执行</strong></p>
                        <figure class="highlight python">
                          <table>
                            <tr>
                              <td class="gutter">
                                <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre>
                              </td>
                              <td class="code">
                                <pre><span class="line"><span class="keyword">from</span> bcy_downloader <span class="keyword">import</span> Downloader</span><br><span class="line"></span><br><span class="line"><span class="comment"># 实例化Downloader对象</span></span><br><span class="line"><span class="comment"># 用户名: test</span></span><br><span class="line"><span class="comment"># 密码: 123</span></span><br><span class="line"><span class="comment"># coser_id: 770554</span></span><br><span class="line"><span class="comment"># 下载目录: E:/banciyuan</span></span><br><span class="line">dl = Downloader(account=<span class="string">'test'</span>, password=<span class="string">'123'</span>, coser_id=<span class="string">'770554'</span>, bcy_home_dir=<span class="string">'E:/banciyuan'</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 获取作品url列表</span></span><br><span class="line">dl.get_post_url_list()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 或者自定义下载作品列表</span></span><br><span class="line">dl.post_url_list = [<span class="string">"https://bcy.net/item/detail/6558754255610577155"</span>, <span class="string">"https://bcy.net/item/detail/6554677621064466692"</span>]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看作品url列表</span></span><br><span class="line">print(dl.post_url_list)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看本地已下载作品url列表</span></span><br><span class="line">print(dl.local_post_url_list)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 获取每个作品下所有图片url，得到download_data</span></span><br><span class="line">dl.get_pics_url_list()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看download_data</span></span><br><span class="line"><span class="comment"># 格式如下</span></span><br><span class="line"><span class="comment"># &#123;</span></span><br><span class="line"><span class="comment">#   '$(post_url)':</span></span><br><span class="line"><span class="comment">#   &#123;</span></span><br><span class="line"><span class="comment">#     'post_name': $(post_name),</span></span><br><span class="line"><span class="comment">#     'pics_url_list': $(pics_url_list)</span></span><br><span class="line"><span class="comment">#   &#125;</span></span><br><span class="line"><span class="comment"># &#125;</span></span><br><span class="line"><span class="comment"># 例子:</span></span><br><span class="line"><span class="comment"># &#123;</span></span><br><span class="line"><span class="comment">#   "https://bcy.net/item/detail/6558754255610577155":</span></span><br><span class="line"><span class="comment">#   &#123;</span></span><br><span class="line"><span class="comment">#     'post_name': "碧蓝航线-COS-舰娘-场照-返图-cp22-三三笠",</span></span><br><span class="line"><span class="comment">#     'pics_url_list': [</span></span><br><span class="line"><span class="comment">#       'https://img5.bcyimg.com/user/770554/item/c0je3/63y6vuq8hhgfmge7nrqcaqkpspyfszj5.jpg?1',</span></span><br><span class="line"><span class="comment">#       'https://img9.bcyimg.com/user/770554/item/c0je3/esdrtvchzzkfzm74ezd8idx04ennjjfr.jpg?2',</span></span><br><span class="line"><span class="comment">#       ......</span></span><br><span class="line"><span class="comment">#       'https://img9.bcyimg.com/user/770554/item/c0je3/zfiyptpdcpasyz0itzh7ndtmpiysw8uy.jpg?9'</span></span><br><span class="line"><span class="comment">#     ]</span></span><br><span class="line"><span class="comment">#   &#125;</span></span><br><span class="line"><span class="comment"># &#125;</span></span><br><span class="line">print(dl.download_data)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 根据download_data获取图片</span></span><br><span class="line">dl.get_pics()</span><br></pre>
                              </td>
                            </tr>
                          </table>
                        </figure>
                        <p> <strong>一键执行</strong></p>
                        <figure class="highlight python">
                          <table>
                            <tr>
                              <td class="gutter">
                                <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre>
                              </td>
                              <td class="code">
                                <pre><span class="line"><span class="keyword">from</span> bcy_downloader <span class="keyword">import</span> Downloader</span><br><span class="line"></span><br><span class="line"><span class="comment"># 实例化Downloader对象</span></span><br><span class="line"><span class="comment"># 用户名: test</span></span><br><span class="line"><span class="comment"># 密码: 123</span></span><br><span class="line"><span class="comment"># coser_id: 770554</span></span><br><span class="line"><span class="comment"># 下载目录: E:/banciyuan</span></span><br><span class="line">dl = Downloader(account=<span class="string">'test'</span>, password=<span class="string">'123'</span>, coser_id=<span class="string">'770554'</span>, bcy_home_dir=<span class="string">'E:/banciyuan'</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 自动下载</span></span><br><span class="line">dl.run()</span><br></pre>
                              </td>
                            </tr>
                          </table>
                        </figure>
                      </li>
                    </ul>
                    <h2 id="注意"><a href="#注意" class="headerlink"
                                                                                                      title="注意"></a>注意
                    </h2>
                    <p><code>v2.0</code>版本下载时会在 <strong>每个作品对应的文件夹</strong>
                      里建一个<code>url.local</code>文件，里面写入的是该作品对应的<code>url</code>。该文件主要用于
                      <strong>判断本地是否已经下载过该<code>url</code>对应的作品，以实现智能无重复下载，请不要随意删除</strong>
                    </p>
                    <h1 id="FAQ"><a href="#FAQ" class="headerlink"
                                                                                                      title="FAQ"></a>FAQ
                    </h1>
                    <p>有何疑问可在<a href="https://github.com/tankeryang/banciyuan-downloader" target="_blank"
                                                                                                      rel="noopener">github</a>发布<a
                                                                                                      href="https://github.com/tankeryang/banciyuan-downloader/issues"
                                                                                                      target="_blank"
                                                                                                      rel="noopener">issue</a>
                      ，本人会尽量及时查看</p>

                  </div>

                  <div>

                    <div>

                      <div
                                                                                                      style="text-align:center;color: #ccc;font-size:14px;">
                        ---------------------------------END---------------------------------
                      </div>

                    </div>

                  </div>

                  <div>
                    <div
                                                                                                    style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
                      <div>手抖一下？</div>
                      <button id="rewardButton" disable="enable"
                                                                                                      onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
                        <span>献爱心</span>
                      </button>
                      <div id="QR" style="display: none;">

                        <div id="wechat" style="display: inline-block">
                          <img id="wechat_qr" src="/images/wx_pay1.png"
                                                                                                          alt="tankeryang WechatPay">
                          <p>WechatPay</p>
                        </div>

                      </div>
                    </div>

                  </div>

                  <footer class="post-footer">

                    <div class="post-tags">

                      <a href="/tags/python/" rel="tag"><i
                                                                                                        class="fa fa-tag"></i>
                        python</a>

                      <a href="/tags/爬虫/" rel="tag"><i class="fa fa-tag"></i>
                        爬虫</a>

                      <a href="/tags/二次元/" rel="tag"><i class="fa fa-tag"></i>
                        二次元</a>

                    </div>

                    <div class="post-widgets">

                      <div id="needsharebutton-postbottom">
                        <span class="btn">
                          <i class="fa fa-share-alt" aria-hidden="true"></i>
                        </span>
                      </div>

                    </div>

                    <div class="post-nav">
                      <div class="post-nav-next post-nav-item">

                        <a href="/posts/python模块fabric踩坑记录/" rel="next"
                                                                                                        title="python模块fabric踩坑记录">
                          <i class="fa fa-chevron-left"></i> python模块fabric踩坑记录
                        </a>

                      </div>

                      <span class="post-nav-divider"></span>

                      <div class="post-nav-prev post-nav-item">

                        <a href="/posts/安装Ubuntu-18-04-LTS之后的N件事/" rel="prev"
                                                                                                        title="安装Ubuntu 18.04 LTS之后的N件事">
                          安装Ubuntu 18.04 LTS之后的N件事 <i
                                                                                                          class="fa fa-chevron-right"></i>
                        </a>

                      </div>
                    </div>

                  </footer>
                </div>

              </article>

              <div class="post-spread">

                <!-- Go to www.addthis.com/dashboard to customize your tools -->
                <div class="addthis_inline_share_toolbox">
                  <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-59b14058bcac3b78"
                                                                                                  async="async">
                  </script>
                </div>

              </div>
            </div>

          </div>

          <div class="comments" id="comments">
          </div>

        </div>

        <div class="sidebar-toggle">
          <div class="sidebar-toggle-line-wrap">
            <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
            <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
            <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
          </div>
        </div>

        <aside id="sidebar" class="sidebar">

          <div id="sidebar-dimmer"></div>

          <div class="sidebar-inner">

            <ul class="sidebar-nav motion-element">
              <li class="sidebar-nav-toc sidebar-nav-active"
                                                                                              data-target="post-toc-wrap">
                文章目录
              </li>
              <li class="sidebar-nav-overview" data-target="site-overview-wrap">
                站点概览
              </li>
            </ul>

            <section class="site-overview-wrap sidebar-panel">
              <div class="site-overview">
                <div class="site-author motion-element" itemprop="author" itemscope
                                                                                                itemtype="http://schema.org/Person">

                  <a href="/" class="site-author-image" rel="start"
                                                                                                  style="border:none">
                    <img class="site-author-image" itemprop="image" src="/uploads/girl.jpeg"
                                                                                                    alt="tankeryang">
                  </a>

                  <p class="site-author-name" itemprop="name">tankeryang</p>
                  <p class="site-description motion-element"
                                                                                                  itemprop="description">
                    汝亦知射乎？吾射不亦精乎？</p>
                </div>

                <nav class="site-state motion-element">

                  <div class="site-state-item site-state-posts">

                    <a href="/archives/">

                      <span class="site-state-item-count">16</span>
                      <span class="site-state-item-name">日志</span>
                    </a>
                  </div>

                  <div class="site-state-item site-state-categories">
                    <a href="/categories/index.html">
                      <span class="site-state-item-count">7</span>
                      <span class="site-state-item-name">分类</span>
                    </a>
                  </div>

                  <div class="site-state-item site-state-tags">
                    <a href="/tags/index.html">
                      <span class="site-state-item-count">28</span>
                      <span class="site-state-item-name">标签</span>
                    </a>
                  </div>

                </nav>

                <div class="links-of-author motion-element">

                  <span class="links-of-author-item">
                    <a href="https://github.com/tankeryang" target="_blank"
                                                                                                    title="GitHub">

                      <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>

                  <span class="links-of-author-item">
                    <a href="mailto:youngzyang@outlook.com" target="_blank"
                                                                                                    title="E-Mail">

                      <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>

                </div>

                <div class="cc-license motion-element" itemprop="license">
                  <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity"
                                                                                                  target="_blank">
                    <img src="/images/cc-by-nc-sa.svg" alt="Creative Commons">
                  </a>
                </div>

                <div
                                                                                                class="links-of-blogroll motion-element links-of-blogroll-block">
                  <div class="links-of-blogroll-title">
                    <i class="fa  fa-fw fa-link"></i>
                    博客镜像 & 友情链接
                  </div>
                  <ul class="links-of-blogroll-list">

                    <li class="links-of-blogroll-item">
                      <a href="https://tankeryang.github.io" title="淦 - github"
                                                                                                      target="_blank">淦
                        - github</a>
                    </li>

                    <li class="links-of-blogroll-item">
                      <a href="https://tankeryang.coding.me" title="淦 - coding"
                                                                                                      target="_blank">淦
                        - coding</a>
                    </li>

                    <li class="links-of-blogroll-item">
                      <a href="http://tankeryang.gitee.io" title="淦 - gitee"
                                                                                                      target="_blank">淦
                        - gitee</a>
                    </li>

                    <li class="links-of-blogroll-item">
                      <a href="https://deeeeeeeee.github.io" title="未知"
                                                                                                      target="_blank">未知</a>
                    </li>

                    <li class="links-of-blogroll-item">
                      <a href="https://www.tiexo.cn/" title="简单可依赖"
                                                                                                      target="_blank">简单可依赖</a>
                    </li>

                    <li class="links-of-blogroll-item">
                      <a href="https://darrenliuwei.com" title="刘伟"
                                                                                                      target="_blank">刘伟</a>
                    </li>

                  </ul>
                </div>

              </div>
            </section>

            <!--noindex-->
            <section
                                                                                            class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
              <div class="post-toc">

                <div class="post-toc-content">
                  <ol class="nav">
                    <li class="nav-item nav-level-1"><a class="nav-link"
                                                                                                      href="#banciyuan-downloader-v2-0"><span
                                                                                                        class="nav-number">1.</span>
                        <span class="nav-text">banciyuan-downloader
                          v2.0</span></a>
                      <ol class="nav-child">
                        <li class="nav-item nav-level-2"><a class="nav-link"
                                                                                                          href="#更新原因"><span
                                                                                                            class="nav-number">1.1.</span>
                            <span class="nav-text">更新原因</span></a></li>
                        <li class="nav-item nav-level-2"><a class="nav-link"
                                                                                                          href="#更新内容"><span
                                                                                                            class="nav-number">1.2.</span>
                            <span class="nav-text">更新内容</span></a>
                          <ol class="nav-child">
                            <li class="nav-item nav-level-3"><a class="nav-link"
                                                                                                              href="#模块化"><span
                                                                                                                class="nav-number">1.2.1.</span>
                                <span class="nav-text">模块化</span></a></li>
                            <li class="nav-item nav-level-3"><a class="nav-link"
                                                                                                              href="#实现功能"><span
                                                                                                                class="nav-number">1.2.2.</span>
                                <span class="nav-text">实现功能</span></a></li>
                            <li class="nav-item nav-level-3"><a class="nav-link"
                                                                                                              href="#依赖的库"><span
                                                                                                                class="nav-number">1.2.3.</span>
                                <span class="nav-text">依赖的库</span></a></li>
                            <li class="nav-item nav-level-3"><a class="nav-link"
                                                                                                              href="#如何使用"><span
                                                                                                                class="nav-number">1.2.4.</span>
                                <span class="nav-text">如何使用</span></a></li>
                          </ol>
                        </li>
                        <li class="nav-item nav-level-2"><a class="nav-link"
                                                                                                          href="#注意"><span
                                                                                                            class="nav-number">1.3.</span>
                            <span class="nav-text">注意</span></a></li>
                      </ol>
                    </li>
                    <li class="nav-item nav-level-1"><a class="nav-link"
                                                                                                      href="#FAQ"><span
                                                                                                        class="nav-number">2.</span>
                        <span class="nav-text">FAQ</span></a></li>
                  </ol>
                </div>

              </div>
            </section>
            <!--/noindex-->

            <div class="back-to-top">
              <i class="fa fa-arrow-up"></i>

              <span id="scrollpercent"><span>0</span>%</span>

            </div>

          </div>
        </aside>

      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <hr>
        <div class="copyright">&copy; 2017 &mdash; <span
                                                                                          itemprop="copyrightYear">2019</span>
          <span class="with-love">
            <i class="fa fa-cog fa-spin fa-1x fa-fw"></i>
          </span>
          <span class="author" itemprop="copyrightHolder">tankeryang</span>

          <span class="post-meta-divider">|</span>
          <span class="post-meta-item-icon">
            <i class="fa fa-area-chart"></i>
          </span>

          <span title="total count">131k</span>

          <span class="post-meta-divider">|</span>
          <span class="post-meta-item-icon">
            <i class="fa fa-coffee"></i>
          </span>

          <span title="total time">4:51</span>

        </div>

        <div class="powered-by">Powered by — <a class="theme-link" target="_blank"
                                                                                          href="https://hexo.io">Hexo</a>
        </div>

        <span class="post-meta-divider">|</span>

        <div class="theme-info">theme &mdash; <a class="theme-link" target="_blank"
                                                                                          href="https://github.com/theme-next/hexo-theme-next">NexT.Mist</a>
          v6.0.1</div>

        <div class="busuanzi-count">
          <script async
                                                                                          src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js">
          </script>

          <span class="site-uv">
            <i class="fa fa-user"></i>
            <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
            visitors
          </span>

        </div>

      </div>
    </footer>

  </div>

  <script type="text/javascript">
    if (Object.prototype.toString.call(window.Promise) !==
      '[object Function]') {
      window.Promise = null;
    }

  </script>

  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  <script type="text/javascript"
                                                                                  src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7">
  </script>

  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1">
  </script>

  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1">
  </script>

  <script type="text/javascript"
                                                                                  src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5">
  </script>

  <script type="text/javascript"
                                                                                  src="/lib/reading_progress/reading_progress.js">
  </script>

  <script type="text/javascript" src="/js/src/utils.js?v=6.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.0.1"></script>

  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.0.1"></script>
  <script type="text/javascript" src="/js/src/post-details.js?v=6.0.1"></script>

  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.0.1"></script>

  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>

  <script type="text/javascript">
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.indexOf(item) > -1;
    });
    new Valine({
      el: '#comments',
      verify: true,
      notify: false,
      appId: 'NiFbgAF3vRyR2BayGJOswb21-gzGzoHsz',
      appKey: 'xGF7qavyOOQGtVACk06SnLrW',
      placeholder: '填上邮箱可以收到回复的邮件提醒哦～',
      avatar: 'retro',
      guest_info: guest,
      pageSize: '10' || 10,
    });

  </script>

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;
    var onPopupClose = function(e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append(
          '<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';
      // start loading animation
      $("body")
        .append(
          '<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css(
        'text-align', 'center');
      // ref: https://github.com/ForbesLindesay/unescape-html
      var unescapeHtml = function(html) {
        return String(html)
          .replace(/&quot;/g, '"')
          .replace(/&#39;/g, '\'')
          .replace(/&#x3A;/g, ':')
          // replace all the other &#x; chars
          .replace(/&#(\d+);/g, function(m, p) {
            return String.fromCharCode(p);
          })
          .replace(/&lt;/g, '<')
          .replace(/&gt;/g, '>')
          .replace(/&amp;/g, '&');
      };
      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content", this).text(),
              url: $("url", this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(
                  /<[^>]+>/g, "");
                content = unescapeHtml(content);
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if (title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text,
                      caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0,
                        position = [],
                        index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word,
                          startPosition)) > -1) {
                        index.push({
                          position: position,
                          word: word
                        });
                        startPosition = position + wordLen;
                      }
                      return index;
                    }
                    indexOfTitle = indexOfTitle.concat(
                      getIndexByWord(keyword,
                        titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(
                      getIndexByWord(keyword,
                        contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent
                    .length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length +
                      indexOfContent.length;
                  }
                }
                // show search results
                if (isMatch) {
                  // sort index by position of keyword
                  [indexOfTitle, indexOfContent].forEach(function(
                    index) {
                    index.sort(function(itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft
                        .position) {
                        return itemRight.position -
                          itemLeft.position;
                      } else {
                        return itemLeft.word.length -
                          itemRight.word.length;
                      }
                    });
                  });
                  // merge hits into slices
                  function mergeIntoSlice(text, start, end,
                  index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index
                      .length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({
                        position: position,
                        length: word.length
                      });
                      var wordEnd = position + word.length;
                      // move to next position of hit
                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }
                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0,
                      title.length, indexOfTitle));
                  }
                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent
                      .length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if (start < 0) {
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if (end > content.length) {
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content,
                      start, end, indexOfContent));
                  }
                  // sort slices in content by search text's count and hits' count
                  slicesOfContent.sort(function(sliceLeft,
                    sliceRight) {
                    if (sliceLeft.searchTextCount !==
                      sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount -
                        sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !==
                      sliceRight.hits.length) {
                      return sliceRight.hits.length -
                        sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight
                        .start;
                    }
                  });
                  // select top N slices in content
                  var upperBound = parseInt('-1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0,
                      upperBound);
                  }
                  // highlight title and content
                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function(hit) {
                      result += text.substring(prevEnd, hit
                        .position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' +
                        text.substring(hit.position, end) +
                        '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }
                  var resultItem = '';
                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl +
                      "' class='search-result-title'>" +
                      highlightKeyword(title, slicesOfTitle[0]) +
                      "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl +
                      "' class='search-result-title'>" + title +
                      "</a>";
                  }
                  slicesOfContent.forEach(function(slice) {
                    resultItem += "<a href='" + articleUrl +
                      "'>" +
                      "<p class=\"search-result\">" +
                      highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });
                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML =
                '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML =
                '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function(resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight
                  .searchTextCount) {
                  return resultRight.searchTextCount - resultLeft
                    .searchTextCount;
                } else if (resultLeft.hitCount !== resultRight
                  .hitCount) {
                  return resultRight.hitCount - resultLeft
                    .hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList =
                '<ul class=\"search-result-list\">';
              resultItems.forEach(function(result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }
          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function(event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }
          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');
          proceedsearch();
        }
      });
    }
    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });
    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e) {
      e.stopPropagation();
    });
    $(document).on('keyup', function(event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });

  </script>

  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>
    AV.initialize("NiFbgAF3vRyR2BayGJOswb21-gzGzoHsz",
      "xGF7qavyOOQGtVACk06SnLrW");

  </script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");
      $visitors.each(function() {
        entries.push($(this).attr("id").trim());
      });
      query.containedIn('url', entries);
      query.find()
        .done(function(results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';
          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }
          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);
            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for (var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if (countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function(object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);
      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(
                  counter.get('time'));
              },
              error: function(counter, error) {
                console.log(
                  'Failed to save Visitor num, with error message: ' +
                  error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(
                  newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }
    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });

  </script>

  <script src="/lib/needsharebutton/needsharebutton.js"></script>

  <script>
    pbOptions = {};
    pbOptions.iconStyle = "box";
    pbOptions.boxForm = "horizontal";
    pbOptions.position = "topCenter";
    pbOptions.networks = "Weibo,Wechat,Douban,QQZone,Twitter,Facebook";
    new needShareButton('#needsharebutton-postbottom', pbOptions);

  </script>

  <script src="/lib/pangu/dist/pangu.min.js?v=3.3"></script>
  <script type="text/javascript">
    pangu.spacingPage();

  </script>

  <script type="text/javascript" src="/js/src/exturl.js?v=6.0.1"></script><!-- hexo-inject:begin --><!-- Begin: Injected MathJax -->
<script type="text/x-mathjax-config">
  MathJax.Hub.Config("");
</script>

<script type="text/x-mathjax-config">
  MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
      all[i].SourceElement().parentNode.className += ' has-jax';
    }
  });
</script>

<script type="text/javascript" src="custom_mathjax_source">
</script>
<!-- End: Injected MathJax -->
<!-- hexo-inject:end -->

</body>

</html>
